package com.redwine.app.net;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.Volley;
import com.redwine.app.APP;
import com.redwine.app.utils.LogUtil;


/**
 * Created by tian on 14-9-17:下午1:08.
 */
public class NetworkHelper {

    private static NetworkHelper mInstance;

    private RequestQueue mRequestQueue;


    private NetworkHelper() {
        VolleyLog.DEBUG = LogUtil.DEBUGGABLE;
        mRequestQueue = getRequestQueue();
    }

    public static NetworkHelper getInstance() {
        return mInstance;
    }
    static{
        init();
    }
    public static void init() {
        mInstance = new NetworkHelper();
    }

    public RequestQueue getRequestQueue() {
        if (mRequestQueue == null) {
            // getApplicationContext() is key, it keeps you from leaking the
            // Activity or BroadcastReceiver if someone passes one in.
            mRequestQueue = Volley.newRequestQueue(APP.getInstance(), new TTHurlStack());
        }
        return mRequestQueue;
    }

    public <T> void addToRequestQueue(Request<T> req) {
        getRequestQueue().add(req);
    }


}
